package fairygui.editor.props
{
   import fairygui.GButton;
   import fairygui.GComboBox;
   import fairygui.GObject;
   import fairygui.PopupMenu;
   import fairygui.editor.ComDocument;
   import fairygui.editor.Consts;
   import fairygui.editor.EditPanel;
   import fairygui.editor.EditorWindow;
   import fairygui.editor.TimelineComponent;
   import fairygui.editor.extui.ColorInput;
   import fairygui.editor.extui.NumericInput;
   import fairygui.editor.gui.EGComponent;
   import fairygui.editor.gui.EGObject;
   import fairygui.editor.gui.ETransition;
   import fairygui.editor.gui.ETransitionItem;
   import fairygui.editor.utils.UtilsStr;
   import fairygui.event.ItemEvent;
   import fairygui.event.StateChangeEvent;
   import flash.events.Event;
   
   public class TransitionFramePropsPanel extends PropsPanel
   {
       
      
      public var lockUpdate:Boolean;
      
      private var _transItem:ETransitionItem;
      
      private var _menu:PopupMenu;
      
      public function TransitionFramePropsPanel(param1:EditorWindow, param2:String)
      {
         super(param1,param2);
      }
      
      override protected function constructFromXML(param1:XML) : void
      {
         var tb:GButton = null;
         var btn:GObject = null;
         var xml:XML = param1;
         super.constructFromXML(xml);
         var cb:GComboBox = getChild("easeType").asComboBox;
         cb.items = Consts.easeType;
         cb.values = Consts.easeType;
         cb.addEventListener(StateChangeEvent.CHANGED,this.__easeTypeChanged);
         cb = getChild("easeInOutType").asComboBox;
         cb.items = Consts.easeInOutType;
         cb.values = Consts.easeInOutType;
         tb = getChild("tween").asButton;
         tb.addClickListener(function():void
         {
            getController("tween").selectedIndex = !!tb.selected?1:0;
         });
         NumericInput(getChild("alpha")).max = 100;
         NumericInput(getChild("volume")).max = 100;
         NumericInput(getChild("x")).min = int.MIN_VALUE;
         NumericInput(getChild("y")).min = int.MIN_VALUE;
         NumericInput(getChild("pivotX")).min = int.MIN_VALUE;
         NumericInput(getChild("pivotY")).min = int.MIN_VALUE;
         with(NumericInput(getChild("rotation")))
         {
            
            min = -int.MAX_VALUE;
            max = int.MAX_VALUE;
         }
         with(NumericInput(getChild("shakePeriod")))
         {
            
            step = 0.1;
            fractionDigits = 2;
         }
         with(NumericInput(getChild("scaleX")))
         {
            
            step = 0.1;
            fractionDigits = 2;
            min = int.MIN_VALUE;
         }
         with(NumericInput(getChild("scaleY")))
         {
            
            step = 0.1;
            fractionDigits = 2;
            min = int.MIN_VALUE;
         }
         with(NumericInput(getChild("pivotX")))
         {
            
            step = 0.1;
            fractionDigits = 2;
            min = int.MIN_VALUE;
         }
         with(NumericInput(getChild("pivotY")))
         {
            
            step = 0.1;
            fractionDigits = 2;
            min = int.MIN_VALUE;
         }
         with(NumericInput(getChild("skewX")))
         {
            
            min = -360;
            max = 360;
         }
         with(NumericInput(getChild("skewY")))
         {
            
            min = -360;
            max = 360;
         }
         with(NumericInput(getChild("repeat")))
         {
            
            step = 1;
            min = -1;
         }
         with(NumericInput(getChild("transTimes")))
         {
            
            step = 1;
            min = -1;
         }
         with(NumericInput(getChild("filter_cb")))
         {
            
            min = -1;
            max = 1;
            step = 0.01;
            fractionDigits = 2;
         }
         with(NumericInput(getChild("filter_cc")))
         {
            
            min = -1;
            max = 1;
            step = 0.01;
            fractionDigits = 2;
         }
         with(NumericInput(getChild("filter_cs")))
         {
            
            min = -1;
            max = 1;
            step = 0.01;
            fractionDigits = 2;
         }
         with(NumericInput(getChild("filter_ch")))
         {
            
            min = -1;
            max = 1;
            step = 0.01;
            fractionDigits = 2;
         }
         this._menu = new PopupMenu();
         this._menu.addItem(Consts.g.text109,this.__clickPivotType);
         this._menu.addItem(Consts.g.text261,this.__clickPivotType);
         this._menu.addItem(Consts.g.text262,this.__clickPivotType);
         this._menu.addItem(Consts.g.text263,this.__clickPivotType);
         this._menu.addItem(Consts.g.text264,this.__clickPivotType);
         btn = getChild("n126");
         btn.addClickListener(function():void
         {
            _menu.show(btn);
         });
      }
      
      override public function update(param1:Vector.<EGObject>) : void
      {
         if(_object)
         {
            _object.statusDispatcher.removeListener(EGObject.XY_CHANGED,this.updateOutline);
            _object.statusDispatcher.removeListener(EGObject.SIZE_CHANGED,this.updateOutline);
         }
         super.update(param1);
         if(param1.length == 1)
         {
            _object.statusDispatcher.addListener(EGObject.XY_CHANGED,this.updateOutline);
            _object.statusDispatcher.addListener(EGObject.SIZE_CHANGED,this.updateOutline);
         }
         this.updateFrame();
      }
      
      private function updateFrame() : void
      {
         var _loc7_:ETransitionItem = null;
         var _loc8_:EGObject = null;
         var _loc9_:GButton = null;
         var _loc10_:GObject = null;
         this.lockUpdate = true;
         var _loc1_:EditPanel = _editorWindow.mainPanel.editPanel;
         var _loc2_:ComDocument = _loc1_.activeDocument as ComDocument;
         var _loc3_:ETransition = _loc2_.editingTransition;
         var _loc4_:int = _loc1_.timelinePanel.head;
         var _loc5_:EGComponent = _loc2_.editingContent;
         var _loc6_:TimelineComponent = _loc1_.timelinePanel.selectedTimeline;
         if(!_loc6_)
         {
            return;
         }
         for each(_loc7_ in _loc3_.items)
         {
            if(_loc7_.frame != _loc4_)
            {
               continue;
            }
            if(_loc6_.targetId != _loc7_.targetId || _loc6_.type != _loc7_.type)
            {
               continue;
            }
            getController("c1").selectedPage = _loc7_.type;
            this._transItem = _loc7_;
            if(_loc7_.targetId)
            {
               _loc8_ = _loc5_.getChildById(_loc7_.targetId);
            }
            else
            {
               _loc8_ = _loc5_;
            }
            _loc9_ = getChild("tween").asButton;
            _loc9_.selected = _loc7_.tween;
            getController("tween").selectedIndex = !!_loc9_.selected?1:0;
            getChild("easeType").asComboBox.value = _loc7_.easeType;
            getChild("easeInOutType").asComboBox.value = _loc7_.easeInOutType;
            getChild("easeInOutType").visible = _loc7_.easeType != "Linear";
            getChild("repeat").text = "" + _loc7_.repeat;
            getChild("yoyo").asButton.selected = _loc7_.yoyo;
            getChild("label").text = _loc7_.label;
            switch(_loc7_.type)
            {
               case "XY":
                  getChild("xEnabled").asButton.selected = _loc7_.value.aEnabled;
                  getChild("yEnabled").asButton.selected = _loc7_.value.bEnabled;
                  _loc10_ = getChild("x");
                  _loc10_.text = "" + int(_loc7_.value.a);
                  _loc10_.enabled = _loc7_.value.aEnabled;
                  _loc10_ = getChild("y");
                  _loc10_.text = "" + int(_loc7_.value.b);
                  _loc10_.enabled = _loc7_.value.bEnabled;
                  continue;
               case "Size":
                  getChild("widthEnabled").asButton.selected = _loc7_.value.aEnabled;
                  getChild("heightEnabled").asButton.selected = _loc7_.value.bEnabled;
                  _loc10_ = getChild("width");
                  _loc10_.text = "" + int(_loc7_.value.a);
                  _loc10_.enabled = _loc7_.value.aEnabled;
                  _loc10_ = getChild("height");
                  _loc10_.text = "" + int(_loc7_.value.b);
                  _loc10_.enabled = _loc7_.value.bEnabled;
                  continue;
               case "Pivot":
                  getChild("pivotX").text = "" + _loc7_.value.a;
                  getChild("pivotY").text = "" + _loc7_.value.b;
                  continue;
               case "Alpha":
                  getChild("alpha").text = "" + Math.round(_loc7_.value.alpha * 100);
                  continue;
               case "Rotation":
                  getChild("rotation").text = "" + _loc7_.value.rotation;
                  continue;
               case "Scale":
                  getChild("scaleX").text = "" + _loc7_.value.a;
                  getChild("scaleY").text = "" + _loc7_.value.b;
                  continue;
               case "Skew":
                  getChild("skewX").text = "" + _loc7_.value.a;
                  getChild("skewY").text = "" + _loc7_.value.b;
                  continue;
               case "Color":
                  ColorInput(getChild("color")).argb = _loc7_.value.color;
                  continue;
               case "Animation":
                  getChild("frameEnabled").asButton.selected = _loc7_.value.aEnabled;
                  getChild("playing").asButton.selected = _loc7_.value.playing;
                  _loc10_ = getChild("frame");
                  _loc10_.enabled = _loc7_.value.aEnabled;
                  _loc10_.text = "" + _loc7_.value.frame;
                  continue;
               case "Sound":
                  getChild("sound").text = _loc7_.value.sound;
                  getChild("volume").text = "" + _loc7_.value.volume;
                  continue;
               case "Transition":
                  getChild("transName").text = _loc7_.value.transName;
                  getChild("transTimes").text = "" + _loc7_.value.transTimes;
                  continue;
               case "Shake":
                  getChild("shakeAmplitude").text = "" + _loc7_.value.shakeAmplitude;
                  getChild("shakePeriod").text = "" + _loc7_.value.shakePeriod;
                  continue;
               case "Visible":
                  getChild("visible").asButton.selected = _loc7_.value.visible;
                  continue;
               case "ColorFilter":
                  NumericInput(getChild("filter_cb")).value = _loc7_.value.filter_cb;
                  NumericInput(getChild("filter_cc")).value = _loc7_.value.filter_cc;
                  NumericInput(getChild("filter_ch")).value = _loc7_.value.filter_ch;
                  NumericInput(getChild("filter_cs")).value = _loc7_.value.filter_cs;
                  continue;
               default:
                  continue;
            }
         }
         this.lockUpdate = false;
      }
      
      override protected function __propChanged(param1:Event) : void
      {
         var _loc6_:String = null;
         var _loc7_:String = null;
         var _loc8_:GObject = null;
         if(this.lockUpdate)
         {
            return;
         }
         var _loc2_:EditPanel = _editorWindow.mainPanel.editPanel;
         var _loc3_:ComDocument = _loc2_.activeDocument as ComDocument;
         var _loc4_:ETransition = _loc3_.editingTransition;
         var _loc5_:GObject = GObject(param1.currentTarget);
         switch(_loc5_.name)
         {
            case "tween":
               _loc4_.setItemProperty(this._transItem,"tween",_loc5_.asButton.selected);
               _loc4_.arrangeItems();
               _loc2_.timelinePanel.refreshTimeline2(this._transItem.targetId,this._transItem.type);
               break;
            case "easeType":
               _loc4_.setItemProperty(this._transItem,"easeType",_loc5_.text);
               break;
            case "easeInOutType":
               _loc4_.setItemProperty(this._transItem,"easeInOutType",_loc5_.text);
               break;
            case "repeat":
               _loc4_.setItemProperty(this._transItem,"repeat",NumericInput(_loc5_).value);
               break;
            case "yoyo":
               _loc4_.setItemProperty(this._transItem,"yoyo",GButton(_loc5_).selected);
               break;
            case "label":
               _loc4_.setItemProperty(this._transItem,"label",UtilsStr.trim(_loc5_.text));
               break;
            default:
               _loc6_ = this._transItem.value.encode(this._transItem.type);
               switch(this._transItem.type)
               {
                  case "XY":
                     this._transItem.value.aEnabled = getChild("xEnabled").asButton.selected;
                     this._transItem.value.bEnabled = getChild("yEnabled").asButton.selected;
                     _loc8_ = getChild("x");
                     this._transItem.value.a = NumericInput(_loc8_).value;
                     _loc8_.enabled = this._transItem.value.aEnabled;
                     _loc8_ = getChild("y");
                     this._transItem.value.b = NumericInput(_loc8_).value;
                     _loc8_.enabled = this._transItem.value.bEnabled;
                     break;
                  case "Size":
                     this._transItem.value.aEnabled = getChild("widthEnabled").asButton.selected;
                     this._transItem.value.bEnabled = getChild("heightEnabled").asButton.selected;
                     _loc8_ = getChild("width");
                     this._transItem.value.a = NumericInput(_loc8_).value;
                     _loc8_.enabled = this._transItem.value.aEnabled;
                     _loc8_ = getChild("height");
                     this._transItem.value.b = NumericInput(_loc8_).value;
                     _loc8_.enabled = this._transItem.value.bEnabled;
                     break;
                  case "Pivot":
                     this._transItem.value.a = NumericInput(getChild("pivotX")).value;
                     this._transItem.value.b = NumericInput(getChild("pivotY")).value;
                     break;
                  case "Alpha":
                     this._transItem.value.alpha = NumericInput(getChild("alpha")).value / 100;
                     break;
                  case "Rotation":
                     this._transItem.value.rotation = NumericInput(getChild("rotation")).value;
                     break;
                  case "Scale":
                     this._transItem.value.a = NumericInput(getChild("scaleX")).value;
                     this._transItem.value.b = NumericInput(getChild("scaleY")).value;
                     break;
                  case "Skew":
                     this._transItem.value.a = NumericInput(getChild("skewX")).value;
                     this._transItem.value.b = NumericInput(getChild("skewY")).value;
                     break;
                  case "Color":
                     this._transItem.value.color = ColorInput(getChild("color")).argb;
                     break;
                  case "Animation":
                     this._transItem.value.aEnabled = getChild("frameEnabled").asButton.selected;
                     _loc8_ = getChild("frame");
                     this._transItem.value.frame = NumericInput(_loc8_).value;
                     _loc8_.enabled = this._transItem.value.aEnabled;
                     this._transItem.value.playing = getChild("playing").asButton.selected;
                     break;
                  case "Sound":
                     this._transItem.value.sound = getChild("sound").text;
                     this._transItem.value.volume = NumericInput(getChild("volume")).value;
                     break;
                  case "Transition":
                     this._transItem.value.transName = getChild("transName").text;
                     this._transItem.value.transTimes = NumericInput(getChild("transTimes")).value;
                     break;
                  case "Shake":
                     this._transItem.value.shakeAmplitude = NumericInput(getChild("shakeAmplitude")).value;
                     this._transItem.value.shakePeriod = NumericInput(getChild("shakePeriod")).value;
                     break;
                  case "Visible":
                     this._transItem.value.visible = getChild("visible").asButton.selected;
                     break;
                  case "ColorFilter":
                     this._transItem.value.filter_cb = NumericInput(getChild("filter_cb")).value;
                     this._transItem.value.filter_cc = NumericInput(getChild("filter_cc")).value;
                     this._transItem.value.filter_ch = NumericInput(getChild("filter_ch")).value;
                     this._transItem.value.filter_cs = NumericInput(getChild("filter_cs")).value;
               }
               _loc7_ = this._transItem.value.encode(this._transItem.type);
               _editorWindow.activeComDocument.actionHistory.action_transItemSet(this._transItem,null,_loc6_,_loc7_);
               _loc4_.setCurFrame(_loc2_.timelinePanel.head);
         }
         _loc3_.setModified();
      }
      
      private function updateOutline() : void
      {
         if(!parent)
         {
            return;
         }
         if(_object.parent == null && !this._transItem.targetId || _object.id == this._transItem.targetId)
         {
            if(this._transItem.type == "XY")
            {
               getChild("x").text = "" + int(this._transItem.value.a);
               getChild("y").text = "" + int(this._transItem.value.b);
            }
            if(this._transItem.type == "Size")
            {
               getChild("width").text = "" + int(this._transItem.value.a);
               getChild("height").text = "" + int(this._transItem.value.b);
            }
         }
      }
      
      private function __easeTypeChanged(param1:Event) : void
      {
         getChild("easeInOutType").visible = getChild("easeType").asComboBox.value != "Linear";
      }
      
      private function __clickPivotType(param1:ItemEvent) : void
      {
         var _loc6_:EGObject = null;
         if(this.lockUpdate)
         {
            return;
         }
         var _loc2_:EditPanel = _editorWindow.mainPanel.editPanel;
         var _loc3_:ComDocument = _loc2_.activeDocument as ComDocument;
         var _loc4_:ETransition = _loc3_.editingTransition;
         var _loc5_:EGComponent = _loc3_.editingContent;
         if(this._transItem.targetId)
         {
            _loc6_ = _loc5_.getChildById(this._transItem.targetId);
         }
         else
         {
            _loc6_ = _loc5_;
         }
         var _loc7_:String = this._transItem.value.encode(this._transItem.type);
         var _loc8_:int = this._menu.list.getChildIndex(param1.itemObject);
         switch(_loc8_)
         {
            case 0:
               this._transItem.value.a = 0.5;
               this._transItem.value.b = 0.5;
               break;
            case 1:
               this._transItem.value.a = 0;
               this._transItem.value.b = 0;
               break;
            case 2:
               this._transItem.value.a = 1;
               this._transItem.value.b = 0;
               break;
            case 3:
               this._transItem.value.a = 0;
               this._transItem.value.b = 1;
               break;
            case 4:
               this._transItem.value.a = 1;
               this._transItem.value.b = 1;
         }
         _loc3_.setModified();
         var _loc9_:String = this._transItem.value.encode(this._transItem.type);
         _editorWindow.activeComDocument.actionHistory.action_transItemSet(this._transItem,null,_loc7_,_loc9_);
         getChild("pivotX").text = "" + this._transItem.value.a;
         getChild("pivotY").text = "" + this._transItem.value.b;
      }
   }
}
